<?php
/* --------------------------------------------------------------
   attributes_weight_calculator.php 2009-12-03 gm
   Gambio GmbH
   http://www.gambio.de
   Copyright (c) 2009 Gambio GmbH
   Released under the GNU General Public License (Version 2)
   [http://www.gnu.org/licenses/gpl-2.0.html]
   --------------------------------------------------------------
*/
?><?php

require_once(DIR_FS_CATALOG . 'gm/inc/gm_prepare_number.inc.php');

if(defined('_GM_VALID_CALL') === false) die('x0');

$products_data = array();
$products_data = $_POST;

$gm_query = xtc_db_query("
						SELECT
							products_weight		AS weight
						FROM
							products
						WHERE
							products_id			= '" . (int)$products_data['products_id']	. "'
						");

$gm_array = xtc_db_fetch_array($gm_query);
if(!empty($products_data['id'])) {
	foreach($products_data['id'] as $key => $unit) {
		$gm_query = xtc_db_query("
								SELECT
									options_values_weight	AS weight,
									weight_prefix			AS prefix
								FROM
									products_attributes
								WHERE
									products_id				= '" . (int)$products_data['products_id']	. "'
								AND
									options_id				= '" . (int)$key								. "'
								AND
									options_values_id		= '" . (int)$unit							. "'
								");
		$row = xtc_db_fetch_array($gm_query);
		if($row['prefix'] == '-') {
			$gm_array['weight'] -= $row['weight'];
		} else {
			$gm_array['weight'] += $row['weight'];
		}
	}
}
echo gm_prepare_number($gm_array['weight'], $xtPrice->currencies[$xtPrice->actualCurr]['decimal_point']);

?>